package com.Brave.manager.dao;

import com.Brave.manager.daomian.Teacher;

public class TeacherDao {
    private static Teacher[] Teachers = new Teacher[7];

    static {
        Teacher tea1 = new Teacher("001", "胖鸡", "18", "男");
        Teachers[0] = tea1;
    }

    public Teacher[] findAllTeacher() {
        return Teachers;
    }

    public boolean addTeacher(Teacher tea) {
        int index = -1;
        for (int i = 0; i < Teachers.length; i++) {
            Teacher Tea = Teachers[i];
            if (Tea == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            Teachers[index] = tea;
            return true;
        }
    }

    public void deleteTeacher(String id) {
        int index = getIndex(id);
        Teachers[index] = null;
    }

    private int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < Teachers.length; i++) {
            Teacher tea = Teachers[i];
            if (tea != null && tea.getId().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public void updateTeacher(String id, Teacher tea) {
        int index = getIndex(id);
        Teachers[index] = tea;
    }
}
